package net.lcheng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.lcheng.commons.utils.PageList;
import net.lcheng.dao.UserWithdrawalsRecordMapper;
import net.lcheng.model.UserWithdrawalsRecord;
import net.lcheng.model.UserWithdrawalsRecordExample;
import net.lcheng.service.UserWithdrawalsRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zwr on 2016/7/8 0008.
 */
@Service
public class UserWithdrawalsRecordServiceImpl implements UserWithdrawalsRecordService {
 @Resource
  private UserWithdrawalsRecordMapper mapper;
    @Override
    public int addWithdrawalsRecord(UserWithdrawalsRecord userWithdrawalsRecord) {
        return mapper.insert(userWithdrawalsRecord);
    }

    @Override
    public PageList<UserWithdrawalsRecord> getUserWithdrawalsRecordByUserId(int pageIndex, int pageSize, String userId) {
        PageHelper.startPage(pageIndex,pageSize);
        UserWithdrawalsRecordExample example=new UserWithdrawalsRecordExample();
        example.or().andUserIdEqualTo(userId);
        List<UserWithdrawalsRecord> list = mapper.selectByExample(example);
        PageInfo<UserWithdrawalsRecord> pageInfo = new PageInfo<>(list);
        PageList<UserWithdrawalsRecord> pageList = new PageList<>();
        pageList.list = pageInfo.getList();
        pageList.totalCount = pageInfo.getTotal();
        pageList.totalPage=pageInfo.getPages();
        pageList.pageIndex=pageInfo.getPageNum();
        pageList.pageSize=pageInfo.getPageSize();
        return pageList;
    }

    @Override
    public List<UserWithdrawalsRecord> getUserWithdrawalsRecordByUserId(String userId) {
        UserWithdrawalsRecordExample example=new UserWithdrawalsRecordExample();
        example.or().andUserIdEqualTo(userId);
        return mapper.selectByExample(example);
    }

    @Override
    public UserWithdrawalsRecord getUserWithdrawalsRecordById(String Id) {
        return mapper.selectByPrimaryKey(Id);
    }
}
